package network;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import protocol.ProtocolEngine;

/**
 * @author Peter Nikodem
 */
public class ClientSender extends Thread {

    private final Socket socket;
    private final ProtocolEngine protocol;
    private PrintWriter out;

    ClientSender(Socket socket, ProtocolEngine protocol) {
        this.socket = socket;
        this.protocol = protocol;
    }

    @Override
    public void run() {
        try {
            out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
        } catch (IOException ex) {
            protocol.connectionInterrupted();
            return;
        }
        try {
            while (!isInterrupted()) {
                String message = getNextMessageFromQueue();
                sendMessageToClient(message);
            }
        } catch (Exception e) {
        }

    }

    private synchronized String getNextMessageFromQueue() {
        
        return null;
    }

    private void sendMessageToClient(String message) {
        out.println(message);
        out.flush();
    }
}
